﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HANS_BackStage.Model.DbModel;
using HANS_BackStage.Common;
using HANS_BackStage.Impl;

namespace HANS_BackStage.Model.WebModel
{
    public   class Login_AdminInfo
    {

        public Login_AdminInfo(Backstage_admin admin, List<Backstage_role> role, List<Perissions> permission,string roleType)
        {
            adminEntity = admin;
            Logindate = DateTime.Now;
            AllRoles = role;
            AllPermissions = permission;
            AllMenuItems = SetMenuItems(permission);
            NowRole = AllRoles.Find(r => r.Id == roleType);
            NowPermission = Role_PermiServices.GetPermissions(Role_PermiServices.GetPermissions(NowRole.Id));
            NowMenuItems = MenuHelper.BuildAdminMenu(NowPermission);
        }


        /// <summary>
        ///  管理员账号
        /// </summary>	
        [DisplayName("管理员账号")]
        public String Name { get {
                return adminEntity.Name;
            } }
        /// <summary>
        ///  管理员昵称
        /// </summary>		
        [DisplayName("管理员昵称")]
        public String Nickname { get {
                return adminEntity.Nickname;
            } }
        /// <summary>
        ///  真实姓名
        /// </summary>		
        [DisplayName("真实姓名")]
        public String Truename { get {
                return adminEntity.Truename;
            } }
        /// <summary>
        ///  性别
        /// </summary>		
        [DisplayName("性别")]
        public string Sex { get {
                string sex = string.Empty;
                switch (adminEntity.Sex.ToString())
                {
                    case "1": sex ="男";break;
                    case "2": sex= "女"; break;
                    case "0": sex ="不详"; break;
                }
                return sex;
            } }
        /// <summary>
        ///  年龄
        /// </summary>		
        [DisplayName("年龄")]
        public Int32? Age { get {
                return adminEntity.Age;
            } }
        /// <summary>
        ///  
        /// </summary>		
        [DisplayName("创建时间")]
        public DateTime? Createlogindate { get {
                return adminEntity.Createlogindate;
            } }
        /// <summary>
        ///  
        /// </summary>		
        [DisplayName("")]
        public String Createby { get {
                return adminEntity.Createby;
            } }
        /// <summary>
        ///  
        /// </summary>		
        [DisplayName("")]
        public DateTime? Lastlogindate { get {
                return adminEntity.Lastlogindate;
            } }
        [DisplayName("登录时间")]
        public DateTime? Logindate { get; set; }

        public  HANS_BackStage.Model.DbModel.Backstage_admin adminEntity { get; private set; }
        public HANS_BackStage.Model.DbModel.Backstage_role NowRole { get; private set; }
        public List<HANS_BackStage.Model.DbModel.Backstage_permission> NowPermission { get; private set; }
        public List<MenuItem> NowMenuItems { get; private set; }


        public List<HANS_BackStage.Model.DbModel.Backstage_role> AllRoles { get; private set; }
        public List<Perissions> AllPermissions { get; private set; }
        public List<MenuItems> AllMenuItems { get; private set; }


        private List<MenuItems> SetMenuItems(List<Perissions> allPermissions) {
            List<MenuItems> menuitemList = new List<MenuItems>();
            foreach (var item in allPermissions)
            {
                MenuItems menutems = new MenuItems();
                menutems.menuItems= MenuHelper.BuildAdminMenu(item.permissions);
                menuitemList.Add(menutems);
            }
            return menuitemList; 
        }

    }

    public class Perissions {
        public Perissions() {
            permissions = new List<Backstage_permission>();
            role = new Backstage_role();
        }
        public Perissions(Backstage_role backstage_role)
        {
            permissions = new List<Backstage_permission>();
            role = backstage_role;
        }
        public List<Backstage_permission> permissions { get; set; }
        public Backstage_role role { get; private set; }
    }
    public class MenuItems {
        public MenuItems() {
            menuItems = new List<WebModel.MenuItem>();
        }
        public List<MenuItem> menuItems { get; set; }
    }
}
